/**
 * Moondance UML modeling tool
 * 
 * This program is free software; you can redistribute it and
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package ro.pub.cs.se.moondance.model;

import org.eclipse.swt.graphics.Image;

public class ClassVariable extends UMLEntity {
	private static final long serialVersionUID = 6380492835663336331L;
	private String name;
	private String type;
	private String visibility;
	private String initialValue;
	private boolean isStaticAttribute;
	private int multiplicity;

	private static final Image ICON = createImage("icons/class_components/variable_small.gif");

	// visiblity <<static>> name : type[multiplicity] = initialValue

	public ClassVariable() {
		super();
	}

	public ClassVariable(String name, String type, int multiplicity,
			String visibility, String initialValue, boolean isStatic) {
		super();
		this.name = name;
		this.type = type;
		this.visibility = visibility;
		this.initialValue = initialValue;
		this.multiplicity = multiplicity;
		this.isStaticAttribute = isStatic;
	}

	public void setVisibility(String visibility) {
		this.visibility = visibility;
	}

	public void setStatic(boolean isStatic) {
		this.isStaticAttribute = isStatic;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setMultiplicity(int multiplicity) {
		this.multiplicity = multiplicity;
	}

	public void setInitialValue(String initialValue) {
		this.initialValue = initialValue;
	}

	public String getName() {
		return name;
	}

	public String getType() {
		return type;
	}

	public String getVisibility() {
		return visibility;
	}

	public boolean isStatic() {
		return isStaticAttribute;
	}

	public int getMultiplicity() {
		return multiplicity;
	}

	public String getInitialValue() {
		return initialValue;
	}

	// visiblity <<static>> name : type[multiplicity] = initialValue
	public String getLabelText() {
		String labelText = visibility + " ";
		if (isStaticAttribute)
			labelText += "<<static>> ";
		labelText += name + ":" + type;
		if (multiplicity != -1)
			labelText += "[" + multiplicity + "]";
		if (initialValue != null && initialValue.length() > 0)
			labelText += "=" + initialValue;
		return labelText;
	}

	public Image getIcon() {
		return ICON;
	}

	public String toString() {
		return name;
	}

	public boolean equals(Object o) {
		if (o == null || !(o instanceof ClassVariable))
			return false;
		ClassVariable at = (ClassVariable) o;
		String text1 = getLabelText();
		String text2 = at.getLabelText();
		return text1.equals(text2);
	}
}
